#meta-description: 敌人采取行动时的行为逻辑
extends Action

@export var attack := 4

func performAction():
  if !enemy or !target: return
  var tween = create_tween().set_trans(Tween.TRANS_QUINT)
  var start = enemy.global_position
  var end = target.global_position + Vector2.RIGHT * 32

  var damage := Damage.new()
  var targets: Array[Node] = [target]
  damage.amount = attack
  damage.sound = sound

  tween.tween_property(enemy, "global_position", end, 0.4)
  tween.tween_callback(damage.execute.bind(targets))
  tween.tween_interval(0.35)
  tween.tween_callback(damage.execute.bind(targets))
  tween.tween_interval(0.25)
  tween.tween_property(enemy, "global_position", start, 0.4)

  tween.finished.connect(
    func(): Events.actionCompleted.emit(enemy)
  )
